import { notification } from 'ant-design-vue';
// import { ElNotification } from 'element-plus'
import { dayjs } from 'element-plus';

type NotificationType = 'success' | 'info' | 'warning' | 'error';
export default class Utils {
  // 全局提示
  static openNotification = (type: NotificationType, message: string) => {
    notification[type]({
      message: message,
    });
  };
  // 数字进位
  static getFormatNumber = (dataSize: number) => {
    dataSize = Number(dataSize)
    if (dataSize < 10000) {
      return dataSize
    } else if (dataSize > 10000 && dataSize < 100000000) {
      return Number((dataSize / 10000).toFixed(2)) + '万'
    } else {
      return Number((dataSize / 100000000).toFixed(2)) + '亿'
    }
  }
  // 问候语
  static getSalutation = () => {
    const nowTime = Number(dayjs().format('HH'))
    if (nowTime > 6 && nowTime <= 8) {
      return '早上好'
    } else if (nowTime > 8 && nowTime <= 11) {
      return '上午好'
    } else if (nowTime > 11 && nowTime <= 14) {
      return '中午好'
    } else if (nowTime > 14 && nowTime <= 18) {
      return '下午好'
    } else if (nowTime > 18 && nowTime <= 24) {
      return '晚上好'
    } else {
      return '夜深了'
    }
  }
  static LocalStore = {
    set(key: string, data: any) {
      localStorage.setItem(
        key,
        typeof data === 'string' ? data : JSON.stringify(data),
      )
    },
    get(key: string) {
      const dataStr = localStorage.getItem(key)
      try {
        if (dataStr) {
          const data = JSON.parse(dataStr)
          return data && typeof data === 'object' ? data : dataStr
        } else {
          return dataStr
        }
      } catch (e) {
        return dataStr
      }
    },
    remove(key: string) {
      localStorage.removeItem(key)
    },
    removeAll() {
      localStorage.clear()
    },
  }
  // 获取日期
  static getFormatDate = (date: string) => dayjs(date).format('YYYY-MM-DD')
  // 处理歌词时间
  static getFormatLyricTime = (time: number) => {
    const minute = parseInt(String(time / 60))
    const second = parseInt(String(time % 60))
    return `${minute < 10 ? '0' + minute : minute}:${second < 10 ? '0' + second : second}`
  }
}
